import requests
import matplotlib.pyplot as plt
import tushare as ts

class autoOrder(object):

    def __init__(self, code):
        self.pro = ts.pro_api('4552d85ac2d1492fc488a32646b501ed6faf1835820f65408790e59d')
        self.code = code
        self.datas = None
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    # 测试验证码方法
    def PostPic(self, im, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
        return r.json()

    def ReportError(self, im_id):
        """
        im_id:报错题目的图片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
        return r.json()



    # 获取日线的数据
    def getDay(self, start, end):
        tu = self.pro
        df = tu.daily(ts_code='300059.SZ', start_date=start, end_date=end)
        return df
        # self.printAllRows(df)




    def plotDF(self, df):
        b = df['close']
        b.plot()
        plt.show()
        # print(type(self.datas['close']))
        # x1 = range(0, 10)
        # x2 = range(0, 10)
        # y2 = [5, 8, 0, 30, 20, 40, 50, 10, 40, 15]
        # plt.plot(x1, y1, label='Frist line', linewidth=3, color='r', marker='o',
        #          markerfacecolor='blue', markersize=12)
        # plt.plot(x2, y2, label='second line')
        # plt.xlabel('Plot Number')
        # plt.ylabel('Important var')
        # plt.title('Interesting Graph\nCheck it out')
        # plt.show()

